<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8" language="java"
	import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>编辑商品详情</title>

		<link type="text/css" href="<%=path%>/manage/css/layout.css" rel="stylesheet" />
		<link type="text/css" href="<%=path%>/manage/css/new_style.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/manage/css/Tooltip.css" />
		<script type="text/javascript" src="<%=path%>/manage/js/jquery-1.4.4.min.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/easyTooltip.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/jquery-ui-1.8.11.custom.min.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/jquery.wysiwyg.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/superfish.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/custom.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/jquery_form.js"></script>
		<%-- 验证js Start --%>
		<script type="text/javascript" src="<%=path%>/manage/js/Tooltip.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/jquery.validate.min.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/jquery.validate.methods.min.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/jquery.validate.defaults.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/errorTip.js"></script>
		<%@ include file="extendsValidator.jspf" %>
		<style type="text/css">
		.btn_add {
			background: url(../images/btn_add.jpg) 0 0 no-repeat;
			border: none;
			color: #F00
		}
		.btn_del {
			background: url(../images/btn_delete.png) 0 0 no-repeat;
			border: none;
			color: #F00
		}
		fieldset{padding:10px;margin:10px;}
		fieldset table tr td{cursor:default;}
		fieldset table tr td input[type="button"]{cursor:POINTER;}
		#preViewArea img{margin:auto 3px;}
		</style>
	</head>
	<script type="text/javascript">
	//提交
	var myForm;
	$(document).ready(function() {
		//验证
		 myForm = $("#myForm").validate({
			rules : {
				"ecProductDto.ecProduct.title" : {
					required : true,
					stringMaxLength : 200
				},
				"ecProductDto.ecProduct.summary" : {
					stringMaxLength : 4000
				},
				"ecProductDto.ecProduct.listPrice" : {
					checkDoubleFmt : [8,2]
				},
				"ecProductDto.ecProduct.price" : {
					required : true,
					checkDoubleFmt : [8,2]
				},
				"ecProductDto.ecProduct.storeQuantity" : {
					required : true,
					checkDoubleFmt : [8,0]
				},
				"ecProductDto.ecProduct.giveUserPoints" : {
					checkDoubleFmt : [8,0]
				},
				"ecProductDto.listPriceName" : {
					required : true
				},
				"ecProductDto.priceName" : {
					required : true
				},
				"ecProductDto.ratingAvgName" : {
					required : true
				},
				"ecProductDto.reviewsCountName" : {
					required : true
				},
				"ecProductDto.orderCountName" : {
					required : true
				},
				"ecProductDto.favCountName" : {
					required : true
				},
				"ecProductDto.commentCountName" : {
					required : true
				},
				"textistoolong" : {
					productContIsTooLong:true
				}

			},
			messages : {
				"ecProductDto.ecProduct.title" : {
					required : "标题必填",
					stringMaxLength:"最长200个字符"
				},
				"ecProductDto.ecProduct.summary" : {
					stringMaxLength:"最长4000个字符"
				},
				"ecProductDto.ecProduct.price" : {
					required : "销售价必填"
				},
				"ecProductDto.ecProduct.storeQuantity" : {
					required: "数量必填",
					checkDoubleFmt : "请输入8位整数"
				},
				"ecProductDto.ecProduct.giveUserPoints" : {
					checkDoubleFmt : "请输入8位整数"
				},
				"ecProductDto.listPriceName" : {
					required : "市场价显示名称必填"
				},
				"ecProductDto.priceName" : {
					required : "销售价显示名称必填"
				},
				"ecProductDto.ratingAvgName" : {
					required : "平均分显示名称必填"
				},
				"ecProductDto.reviewsCountName" : {
					required : "访问量显示名称必填"
				},
				"ecProductDto.orderCountName" : {
					required : "订单数显示名称必填"
				},
				"ecProductDto.favCountName" : {
					required : "收藏人气显示名称必填"
				},
				"ecProductDto.commentCountName" : {
					required : "评论数显示名称必填"
				},
				"textistoolong" : {
					productContIsTooLong:""
				}
			}
		});
	});
	
	function checkImgIsUpload() {
		//缩略图
		if($("#hiddenThumbImg").val()==""){
			alert("请上传缩略图");
			return false;
		}
		//预览图
		var all = $("#preViewArea").children("img").length;
		if(all == 0){
			alert("请至少上传一张预览图");
			return false;
		}
		return true;
	}
	
	function btnSubmit(){
		if(!checkImgIsUpload())
			return;
		if(myForm.valid()){
			$("#myForm").submit();
		}
	}
	function openUpload(dataProcessFunction,type,obj){
		if(type==1){
			var all = $("#preViewArea").children("img").length;
			if(all == 5){
				alert("最多上传5张");
				return;
			}
		}
		resetDialogPosition("preViewArea",100,-50);
		$("#upload").dialog("open");
		if(type==2){
			$("#chanagedImgId").html($(obj).attr("id"));
		}
		$("#dataProcessFunction").html(dataProcessFunction);
	}
	
	function thumbUpload(dataProcessFunction) {
		resetDialogPosition("preViewArea",100,-50);
		$("#upload").dialog("open");
		$("#dataProcessFunction").html(dataProcessFunction);
	}
	
	function contentImgUpload(dataProcessFunction) {
		resetDialogPosition("contentImgAddBtn",200,-200);
		$("#upload").dialog("open");
		$("#dataProcessFunction").html(dataProcessFunction);
	}
	
	function chanteContentImgUpload(dataProcessFunction,obj){
		resetDialogPosition($(obj).attr("id"),100,-200*($("#ecDetailContent tr").length));
		$("#upload").dialog("open");
		$("#chanagedImgId").html($(obj).attr("id"));
		$("#dataProcessFunction").html(dataProcessFunction);
	}
	
	function resetDialogPosition(objId,xOffset,yOffset) {
		var X = $("#"+objId).offset().left+xOffset;
     	var Y = $("#"+objId).offset().top+yOffset;
		$("#upload").dialog('option', 'position', [X,Y]);
	}
	
</script>
	<body>
		<div>
			<p class="sitemap">
				当前位置：应用内容管理 > 商品详情录入
			</p>
			<h1>
				商品详情录入
			</h1>
			<div>
				<!-- Tabs -->
				<div id="tabs">
					<ul>
						<li>
							<a href="#tabs-1">商品详情录入</a>
						</li>

					</ul>
					<%@ include file="gJsVar.jspf" %>
					<%@ include file="imgUp.jspf" %>
					<s:form action="/dataBinding/doEcSave.action" name="myForm"
						id="myForm" enctype="multipart/form-data" method="post">
						<s:hidden name="ecProductDto.intContentId"></s:hidden>
						<s:hidden name="intCateId" ></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.id"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.catId"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.appId"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.publish"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.sortOrders"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.ratingAvg"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.createDt"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.reviewsCount"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.orderCount"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.favCount"></s:hidden>
						<s:hidden name="ecProductDto.ecProduct.commentCount"></s:hidden>
						<!-- First tab -->
						<fieldset>
							<legend>基本信息</legend>
							<div>
								<table cellspacing="0" cellpadding="0" border="0" class="fullwidth" style="border: 0" id="contenttable">
									<tr>
										<td width="15%">
											<span style="color:red">*</span>缩略图
										</td>
										<td>
											<s:hidden name="imgWidth"></s:hidden>
											<s:hidden name="imgHeight"></s:hidden>
											<s:hidden name="imgSize"></s:hidden>
											<div id="thumbImgArea">
												<s:if test="ecProductDto.ecProduct.thumbImage!=null">
													<img title="双击更改" src='<%=serverUrl %><s:property value="ecProductDto.ecProduct.thumbImage" />' ondblClick="thumbUpload('populateChangedThumbImgData')" style="cursor:pointer;" id="titleFile" width="80" height="60">
												</s:if>
												<s:else>
													<input type='button' id="thumbUpBtn" style="margin-left:2px;" value='上传' onClick="thumbUpload('populateThumbImgData')"/>
												</s:else>
												<s:hidden name="ecProductDto.ecProduct.thumbImage" id="hiddenThumbImg"></s:hidden>
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<span style="color:red">*</span>名称
										</td>
										<td>
											<s:textfield name="ecProductDto.ecProduct.title" cssClass="textbox_border" />
										</td>
									</tr>
									<tr>
										<td>
											<span style="color:red">*</span>预览图
										</td>
										<td>
											<div id="preViewArea" style="padding:5px 0 0 0">
												<script>
													function changeMouseStatus(value){
														imgMouseStatus = value;
													}
													function doDelImg(obj) {
														if(imgMouseStatus){
															deleteViewImg(obj);
															imgMouseStatus = false;
														}
													}
													function deleteViewImg(obj){
														var id = $(obj).attr("id");
														var index = id.substring(id.length-1);
														if(index < existViewImgNum){
															var deletedImgId = $("#hiddenImgId"+index).val();
															$("#deletedViewImg").val($("#deletedViewImg").val()+deletedImgId+",");
														}
														$(obj).remove();
														$("#hiddenImg"+index).remove();
														$("#hiddenImgId"+index).remove();
													}
												</script>
												<s:iterator value="ecProductDto.resources" status="proRes">
													<s:if test="#proRes.last" >
														<script>
															viewImgCount=parseInt('${ proRes.count}');
															existViewImgNum=parseInt('${ proRes.count}');
														</script>
													</s:if>
													<img src="<%=serverUrl %><s:property value='mediaUrl' />" onmouseup="changeMouseStatus(false)" onmouseout="doDelImg(this)" onmousedown="changeMouseStatus(true)" style="vertical-align:top;cursor:pointer;" width="80px" height="80px" onDblClick="openUpload('populateChangedImgData',2,this)" title="双击变更,移动删除" id="viewImg<s:property value='#proRes.index'/>" />
													<input type="hidden" name="ecProductDto.resources[<s:property value='#proRes.index'/>].mediaUrl" id="hiddenImg<s:property value='#proRes.index'/>" value="<s:property value='mediaUrl' />" />
													<input type="hidden" name="ecProductDto.resources[<s:property value='#proRes.index'/>].id" id="hiddenImgId<s:property value='#proRes.index'/>" value="<s:property value='id' />" />
												</s:iterator>
											<input type='button' style="margin-left:2px;width:80px;background:#F0F0F0;height:80px;color:#666;font-size:32px;text-shadow:0 2px 2px #FFF;" value='+' id="imgUpBtn" onClick="openUpload('populateViewImgData',1,this)"/>
												<input type="hidden" name="ecProductDto.deletedViewImg" id="deletedViewImg" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											描述
										</td>
										<td>
											<s:textarea name="ecProductDto.ecProduct.summary"
												cssStyle="width:400px; height:70px; " />
										</td>
									</tr>
									
									<tr>
										<td>
											市场价
										</td>
										<td>
											<s:textfield name="ecProductDto.ecProduct.listPrice"></s:textfield>
										</td>
									</tr>
									<tr>
										<td>
											<span style="color:red">*</span>销售价
										</td>
										<td>
											<s:textfield name="ecProductDto.ecProduct.price"></s:textfield>备注：产品以销售价格结算。积分产品直接填写所需积分数。
										</td>
									</tr>
									<tr>
										<td>
											<span style="color:red">*</span>数量
										</td>
										<td>
											<s:textfield name="ecProductDto.ecProduct.storeQuantity"></s:textfield>
										</td>
									</tr>
									<tr>
										<td>
											赠送积分
										</td>
										<td>
											<s:textfield name="ecProductDto.ecProduct.giveUserPoints"></s:textfield>
										</td>
									</tr>
									<tr>
										<td>
											<span style="color:red">*</span>支付方式
										</td>
										<td>
											<s:radio name="ecProductDto.ecProduct.paymentType" theme="simple" list="%{#{'1':'在线支付','2':'货到付款','9':'积分兑换' }}"></s:radio>
										</td>
									</tr>
									<s:hidden name="ecProductDto.ecProduct.isReal"></s:hidden>
									<%-- 
									<tr>
										<td>
											<span style="color:red">*</span>产品形态
										</td>
										<td>
											
											<s:radio name="ecProductDto.ecProduct.isReal" list="%{#{'1':'实物商品','0':'虚拟商品' }}" theme="simple"></s:radio>
											<s:radio name="ecProductDto.ecProduct.isReal" list="%{#{'1':'实物商品' }}" theme="simple"></s:radio>
										</td>
									</tr>
									--%>
								</table>
							</div>
						</fieldset>
						<fieldset>
							<legend>显示字段命名</legend>
							<table cellspacing="0" cellpadding="0" border="0" class="fullwidth" style="border: 0">
								<tr>
									<td width="15%">
										<span style="color:red">*</span>市场价
									</td>
									<td>
										<s:textfield name="ecProductDto.listPriceName"></s:textfield>
									</td>
									<td>
										<span style="color:red">*</span>销售价
									</td>
									<td>
										<s:textfield name="ecProductDto.priceName"></s:textfield>
									</td>
								</tr>
								<tr>
									<s:hidden name="ecProductDto.ratingAvgName"></s:hidden>
									<%-- 
									<td>
										<span style="color:red">*</span>平均分
									</td>
									<td>
										<s:textfield name="ecProductDto.ratingAvgName"></s:textfield>
									</td>
									--%>
									<td>
										<span style="color:red">*</span>评论数
									</td>
									<td>
										<s:textfield name="ecProductDto.commentCountName"></s:textfield>
									</td>
									<td>
										<span style="color:red">*</span>访问量
									</td>
									<td>
										<s:textfield name="ecProductDto.reviewsCountName"></s:textfield>
									</td>
								</tr>
								<tr>
									<td>
										<span style="color:red">*</span>订单数
									</td>
									<td>
										<s:textfield name="ecProductDto.orderCountName"></s:textfield>
									</td>
									<td>
										<span style="color:red">*</span>收藏人气
									</td>
									<td>
										<s:textfield name="ecProductDto.favCountName"></s:textfield>
									</td>
								</tr>
								<%-- 
								<tr>
									<td>
										<span style="color:red">*</span>评论数
									</td>
									<td>
										<s:textfield name="ecProductDto.commentCountName"></s:textfield>
									</td>
								</tr>
								--%>
							</table>
						</fieldset>
						<%--
						<fieldset>
							<legend>扩展字段</legend>
							<%@ include file="attr.jspf" %>
						</fieldset>
						--%>
						<fieldset>
							<legend>商品内容</legend>
							<%@ include file="txtImgArea.jspf" %>
						</fieldset>
						<div align="center">
							<input type="button" value="提交" class="button"
								onclick="btnSubmit();">
						</div>
					</s:form>
					<div id="uploadArea"></div>
				</div>
			</div>
		</div>
	</body>
</html>
